<?php
include 'inc/db_util.php';
$result = mysql_query("SELECT nip, username, namadosen FROM tb_dosen WHERE nip='" . $_SESSION['nip'] . "'");
$user = mysql_fetch_object($result) or die(mysql_error());
?>

<script>
    function logout() {
        $.messager.confirm('Confirmation', 'Anda yakin ingin keluar?', function(option) {
            if (option) {
                document.location = "index.php?page=logoff";
            }
        });
    }
    function change() {
        var nip = $('#nip').val();
        var username = $('#username').val();
        var oldpass = $('#old_password').val();
        var newpass = $('#new_password').val();
        if (!username || !oldpass || !newpass) {
            $.growl({title: "Info", message: "Data tidak boleh kosong!"});
            return false;
        }
        $.messager.confirm('Confirmation', 'Simpan perubahan account?', function(option) {
            if (option) {
                var account = "nip=" + nip + "&username=" + username + "&oldpass=" + oldpass + "&newpass=" + newpass;
                $.ajax({
                    type: "POST",
                    url: "ws/dosen_services.php?action=updateAccount",
                    data: account,
                    success: function(data) {
                        $.growl({title: "Message", message: data});
                    }
                });
            }
        });
    }
</script>

<!-- Panel -->
<div id="toppanel">
    <div id="panel">
        <div class="content clearfix">

            <div class="left right">			
                <h1>Account <?php echo $user->namadosen ?></h1>

                <table class="data-form">
                    <tr>
                        <td>NIP</td>
                        <td><input disabled="true" id="nip" value="<?php echo $user->nip ?>"/></td>
                    </tr>
                    <tr>
                        <td>Username</td>
                        <td><input id="username" value="<?php echo $user->username ?>"/></td>
                    </tr>
                    <tr>
                        <td>Password Lama</td>
                        <td><input type="password" id="old_password" /></td>
                    </tr>
                    <tr>
                        <td>Password Baru</td>
                        <td><input type="password" id="new_password" /></td>
                    </tr>
                </table>

                <ul style="display: inline;float: right; padding-top: 5px">
                    <li style="display: inline-block;"><a href="#" onclick="logout();">Log Off</a></li>
                    <li style="display: inline-block;" class="sep">|</li>
                    <li style="display: inline-block;"><a href="#" onclick="change()">Simpan</a></li>
                </ul>
            </div>

        </div>
    </div> 	
    <!-- The tab on top -->	
    <div class="tab">
        <ul class="login">
            <li class="left">&nbsp;</li>
            <li>Hello <?php echo $_SESSION['username']; ?>!</li>
            <li class="sep">|</li>
            <li id="toggle">
                <a id="open" class="open" href="#">Open Panel</a>
                <a id="close" style="display: none;" class="close" href="#">Close Panel</a>			
            </li>
            <li class="right">&nbsp;</li>
        </ul> 
    </div> <!-- / top -->

</div> <!--panel -->
